package com.thz.friend.controller.video;

import com.thz.common.core.controller.BaseController;
import com.thz.common.core.result.Result;
import com.thz.friend.pojo.video.Video;
import com.thz.friend.service.video.IVideoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @Description
 * @Author thz
 * @Date 2025/5/11
 */
@Slf4j
@RestController
@RequestMapping("/video")
@Tag(name = "视频接口")
public class VideoController extends BaseController {

    @Autowired
    private IVideoService videoService;


    @GetMapping("/list")
    public Result<List<Video>> list(@NonNull @RequestParam("courseId") Long courseId){
        return Result.ok(videoService.list(courseId));
    }

    @GetMapping("/{videoId}")
    @Operation(summary = "获取视频信息")
    public Result<Video> getVideo(@NotNull @RequestParam("videoId") Long videoId,@NonNull @RequestParam("courseId") Long courseId) {
        try {
            Video video = videoService.getVideoById(videoId,courseId);
            if (video == null) {
                return Result.failed("视频不存在");
            }
            return Result.ok(video);
        } catch (Exception e) {
            log.error("Failed to get video", e);
            return Result.failed("获取视频信息失败：" + e.getMessage());
        }
    }
}
